// 新增主体
export default defineEventHandler(async (event) => {
    try {
        const { name, address } = await readBody(event) || {};
        // 1. 校验参数
        createSubjectSchema({ name, address });
        // 2. 连接数据库
        const db = useDatabase();
        // 3. 执行新增操作
        const { rows } = await db.sql`INSERT INTO subject (name, address) VALUES (${name}, ${address})`;
        // 4. 返回结果
        console.log(rows);
        const result = rows[0] as unknown as Subject;
        return sucessResponse(result);
    } catch (error) {
        console.error('create subject error  ', error);
        return catchErrorResponse(error)
    }
});

